package com.feijia.aijingjingus.util;

import com.feijia.aijingjingus.Constants;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by yangshaomin on 2018/8/1.
 */

public class RetrofitUtil {
        public static retrofit2.Retrofit getRetrofit() {
            retrofit2.Retrofit retrofit;
            if (Constants.isPrintLog) {
                //打印网络报文
                OkHttpClient okHttpClient = new OkHttpClient.Builder().addInterceptor
                        (new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)).build();

                retrofit = new retrofit2.Retrofit.Builder()
                        .baseUrl(Constants.URL) // 设置 网络请求 Url
                        .client(okHttpClient)
                        .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                        .addConverterFactory(GsonConverterFactory.create()) //设置使用Gson解析(记得加入依赖)
                        .build();
            } else {
                //不打印网络报文
                retrofit = new retrofit2.Retrofit.Builder()
                        .baseUrl(Constants.URL) // 设置 网络请求 Url
                        .addConverterFactory(GsonConverterFactory.create()) //设置使用Gson解析(记得加入依赖)
                        .build();
            }
            return retrofit;
        }

}
